<template>
  <div class="app-container">
    <el-form :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      class="form-search"
      label-width="160px">
      <!-- <el-form-item :label="$t('payrollT.exchangeName')"
        prop="exchangeName">
        <el-select v-model="queryParams.exchangeId"
          filterable
          remote
          reserve-keyword
          :placeholder="$t('common.placeholderSelect')"
          :remote-method="remoteMethod"
          :loading="exhloading"
          style="width: 240px">
          <el-option v-for="item in exchangeList"
            :key="item.exchangeId"
            :label="item.exchangeName"
            :value="item.exchangeId">
          </el-option>
        </el-select>
      </el-form-item> -->
      <el-form-item :label="$t('payrollT.toBeneName')"
        prop="toBeneName">
        <el-input v-model="queryParams.toBeneName"
          :placeholder="$t('common.placeholderContent')"
          clearable
          style="width: 240px"
          maxlength="50"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item :label="$t('payrollT.toAccountNumber')"
        prop="toAccountNumber">
        <el-input v-model="queryParams.toAccountNumber"
          :placeholder="$t('common.placeholderContent')"
          clearable
          style="width: 240px"
          maxlength="50"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item :label="$t('payrollT.toBeneShortName')"
        prop="toBeneShortName">
        <el-input v-model="queryParams.toBeneShortName"
          :placeholder="$t('common.placeholderContent')"
          clearable
          style="width: 240px"
          maxlength="50"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item :label="$t('payrollT.status')"
        prop="status">
        <el-select v-model="queryParams.status"
          :placeholder="$t('common.placeholderSelect')"
          clearable
          style="width: 240px">
          <el-option v-for="dict in dict.type.transfer_result_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery">{{$t('common.search')}}</el-button>
        <el-button icon="el-icon-refresh"
          size="mini"
          @click="resetQuery">{{$t('common.reset')}}</el-button>
      </el-form-item>
    </el-form>

    <div class="section-box">
      <el-row :gutter="10"
        class="mb8">
        <el-col :span="1.5">
          <el-button type="primary"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleExport">{{$t('common.export')}}</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button type="warning"
            plain
            icon="el-icon-close"
            size="mini"
            @click="handleClose">{{$t('common.close')}}</el-button>
        </el-col>
        <right-toolbar :showSearch.sync="showSearch"
          @queryTable="getList"></right-toolbar>
      </el-row>

      <el-table v-loading="loading"
        :data="detailList">
        <!-- <el-table-column type="selection"
        min-width="55"
        align="center" /> -->
        <el-table-column :label="$t('payrollT.subject')"
          align="center"
          prop="subject"
          min-width="160"
          show-overflow-tooltip />
        <el-table-column :label="$t('payrollT.exchangeName')"
          align="center"
          prop="exchangeName"
          min-width="160"
          show-overflow-tooltip />
        <el-table-column :label="$t('payrollT.toBeneName')"
          align="center"
          prop="toBeneName"
          min-width="160"
          show-overflow-tooltip />
        <el-table-column :label="$t('payrollT.toAccountNumber')"
          align="center"
          prop="toAccountNumber"
          min-width="160"
          show-overflow-tooltip />
        <el-table-column :label="$t('payrollT.toIfscCode')"
          align="center"
          prop="toIfscCode"
          min-width="160"
          show-overflow-tooltip />
        <!-- <el-table-column :label="$t('payrollT.bankName')"
          align="center"
          prop="bankName"
          min-width="160"
          show-overflow-tooltip /> -->
        <el-table-column :label="$t('payrollT.paymentMode')"
          align="center"
          prop="paymentMode"
          min-width="120" />
        <el-table-column :label="$t('payrollT.amount')"
          align="center"
          prop="amount"
          min-width="120" />
        <el-table-column :label="$t('payrollT.transCode')"
          align="center"
          prop="transNo"
          min-width="160"
          show-overflow-tooltip />
        <el-table-column :label="$t('payrollT.transDate')"
          align="center"
          prop="transDate"
          min-width="160" />
        <el-table-column :label="$t('payrollT.transStatus')"
          align="center"
          prop="status"
          :show-overflow-tooltip="true"
          min-width="140">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.transfer_result_status"
              :value="scope.row.status" />
          </template>
        </el-table-column>
        <el-table-column :label="$t('common.createBy')"
          align="center"
          prop="createBy"
          min-width="160"
          show-overflow-tooltip />
        <el-table-column :label="$t('common.createTime')"
          align="center"
          prop="createTime"
          min-width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column :label="$t('common.updateBy')"
          align="center"
          prop="updateBy"
          min-width="160"
          show-overflow-tooltip />
        <el-table-column :label="$t('common.updateTime')"
          align="center"
          prop="updateTime"
          min-width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.updateTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column :label="$t('common.remark')"
          prop="remark"
          min-width="160"
          show-overflow-tooltip />
        <el-table-column :label="$t('common.controls')"
          align="center"
          class-name="small-padding fixed-width"
          fixed="right"
          min-width="140">
          <template slot-scope="scope">
            <el-button size="mini"
              type="text"
              icon="el-icon-view"
              @click="handleView(scope.row)">{{$t('common.view')}}</el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList" />
    </div>

    <!-- 查看详情 -->
    <ViewShow :title="$t('common.viewDetail')"
      :open="showView"
      :dataList="viewList"
      :isLine="true"
      :labelWidth="180"
      width="800"
      @toClose="showView = false" />
  </div>
</template>

<script>
import {
  getPayrollTransferDetailList,
} from "@/api/transaction/payrollTransfer.js";
import {
  getExhUserList,
} from "@/api/system/exchangeUser.js";
import ViewShow from '@/views/components/viewShow.vue'

export default {
  name: "payrollTransfer",
  dicts: ["transfer_result_status"],
  components: { ViewShow },
  data () {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 角色表格数据
      detailList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        toBeneName: null,
        toAccountNumber: null,
        toBeneShortName: null,
        status: null,
        batchId: null,
      },
      batchId: null,
      // 表单参数
      form: {},
      // 表单校验
      rules: {},

      exchangeList: [],
      exhloading: false,
      bankList: [],
      bankLoading: false,
      showView: false,
      viewList: [],
    };
  },
  created () {
    this.batchId = this.$route.params.batchId
    this.queryParams.batchId = this.batchId
    // this.queryParams.exchangeId = this.$route.query.exchangeId
    // this.queryParams.subject = this.$route.query.subject
    this.getList();
  },
  methods: {
    // 搜索汇兑用户
    remoteMethod (query) {
      if (query !== '') {
        this.exhloading = true;
        getExhUserList({
          pageNum: 1,
          pageSize: 10,
          payType: 'payout',
          status: 1,
          exchangeName: query
        }).then(
          (response) => {
            this.exchangeList = response.rows;
            this.exhloading = false;
          }
        );
      } else {
        this.exchangeList = [];
      }
    },
    /** 查询列表 */
    getList () {
      this.loading = true;
      getPayrollTransferDetailList(this.queryParams).then(
        (response) => {
          this.detailList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    // 返回按钮
    handleClose () {
      const obj = { path: '/transaction/payrollTransfer' };
      this.$tab.closeOpenPage(obj);
    },
    // 查看详情
    handleView (row) {
      this.viewList = []
      let statusList = this.dict.type.transfer_result_status
      let viewInfo = row;
      let showData = ['exchangeName', 'amount', 'transNo', 'toBeneName', 'toBeneShortName', 'fromBankName', 'toBankName',
        'fromAccountNumber', 'toAccountNumber', 'fromIfscCode', 'toIfscCode', 'transDate', 'transStatus']
      let commonData = ['remark', 'createBy', 'createTime', 'updateBy', 'updateTime']

      showData.forEach(item => {
        this.viewList.push({
          type: 'text',
          label: this.$t(`payrollT.${item}`) + '：',
          value: item == 'transStatus' ? statusList.filter(i => viewInfo['status'] == i.value)[0].label : viewInfo[item]
        })
      })
      commonData.forEach(item => {
        this.viewList.push({
          type: 'text',
          label: this.$t(`common.${item}`) + '：',
          value: viewInfo[item]
        })
      })
      if (viewInfo.attachment) {
        let imgs = viewInfo.attachment.split(',')
        this.viewList.push({
          type: 'img',
          label: this.$t(`mtd.attachment`) + '：',
          value: imgs
        })
      } else {
        this.viewList.push({
          type: 'img',
          label: this.$t(`mtd.attachment`) + '：',
          value: []
        })
      }

      setTimeout(() => {
        this.showView = true;
      })
    },

    /** 搜索按钮操作 */
    handleQuery () {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery () {
      this.queryParams.exchangeId = null
      this.exchangeList = []
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 导出按钮操作 */
    handleExport () {
      this.download(
        "/md/payeeDetailTransRecord/export",
        {
          ...this.queryParams,
        },
        `payeeDetailTransRecord_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
